package com.hh.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hh.annotation.AuthCheck;
import com.hh.common.BaseResponse;
import com.hh.common.ErrorCode;
import com.hh.common.ResultUtils;
import com.hh.constant.UserConstant;
import com.hh.entity.domain.SysLog;
import com.hh.entity.dto.syslog.SysLogQueryRequest;
import com.hh.exception.ThrowUtils;
import com.hh.service.SysLogService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author hanhui
 * @version 1.0
 * @description: TODO
 * @date 2025/9/14 21:29
 **/
@RestController
@Slf4j
public class SysLogController {
    // TODO 分页+条件查询
    @Resource
    private SysLogService sysLogService;

    @AuthCheck(mustRole = UserConstant.ADMIN_ROLE)
    @GetMapping("/sys/log/list")
    public BaseResponse<Page<SysLog>> getListByPage(SysLogQueryRequest sysLogQueryRequest) {
        ThrowUtils.throwIf(sysLogQueryRequest == null, ErrorCode.PARAMS_NULL, "请求参数不能为空");
        log.info(sysLogQueryRequest.toString());
        QueryWrapper<SysLog> queryWrapper = sysLogService.getQueryWrapper(sysLogQueryRequest);
        Page<SysLog> sysLogPage = sysLogService.page(new Page<>(sysLogQueryRequest.getPageNum(), sysLogQueryRequest.getPageSize()),
                queryWrapper);
        return ResultUtils.success(sysLogPage);
    }
}
